
<!DOCTYPE html>
<html>
<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>传智健康</title>
    <meta name="description" content="传智健康">
    <meta name="keywords" content="传智健康">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../plugins/elementui/index.css">
    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../css/style.css">
    <style type="text/css">
        body, html{width: 100%;height: 100%;margin:0;font-family:"微软雅黑";}
        #l-map{height:500px;width:95%;}
    </style>
    <style>
        .tangram-suggestion {
            z-index: 9999;
        }
    </style>

    <script type="text/javascript" src="http://api.map.baidu.com/api?v=1.2&ak=6FZOFuPWmmgGOvht0obFj9GQtyOenCEZ"></script>
    <!-- 引入组件库 -->
    <script type="text/javascript" src="../js/jquery.min.js"></script>
    <script src="../js/vue.js"></script>
    <script src="../plugins/elementui/index.js"></script>
    <script src="../js/axios-0.18.0.js"></script>
    <style>
        .datatable {
            position: relative;
            box-sizing: border-box;
            -webkit-box-flex: 1;
            width: 100%;
            max-width: 100%;
            font-size: 14px;
            color: rgb(96, 98, 102);
            overflow: hidden;
            flex: 1 1 0%;
        }
        .datatable td, .datatable th {
            padding: 12px 0;
            min-width: 0;
            -webkit-box-sizing: border-box;
            box-sizing: border-box;
            text-overflow: ellipsis;
            vertical-align: middle;
            position: relative;
            text-align: left;
        }
    </style>
    <script type="text/javascript" src="http://api.map.baidu.com/api?v=1.2&ak=6FZOFuPWmmgGOvht0obFj9GQtyOenCEZ"></script>
</head>
<body class="hold-transition" >
<div id="app">
    <div class="content-header">
        <h1>首页<small>公司分布图</small></h1>
        <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>公司分布图</el-breadcrumb-item>
        </el-breadcrumb>
    </div>

    <div class="app-container">
        <div class="box">
            <div class="add-form">
                <template>
                    <el-tabs v-model="activeName" type="card" @tab-click="handleRemove()">
                        <el-tab-pane label="分布图" name="first">
                            <!--<div id="r-result">-->
                            <!--<input type="button" value="分布图" onclick="bdGEO()" />-->
                            <!--<div id="result"></div>-->
                            <!--</div>-->
                            <div id="l-map"></div>
                        </el-tab-pane>

                        <el-tab-pane label="详细信息" name="second">
                            <div class="filter-container">
                                <el-input placeholder="公司地址" v-model="pagination.queryString" style="width: 200px;"></el-input>
                                <el-button @click="findPage()" class="dalfBut">查询</el-button>
                                <el-button type="primary" class="butT" @click="handleCreate()">新建</el-button>
                            </div>

                            <el-table size="small" current-row-key="id" :data="dataList" stripe highlight-current-row>
                                <el-table-column type="index" align="center" label="序号"></el-table-column>
                                <el-table-column prop="address" label="公司地址" align="center"></el-table-column>
                                <el-table-column prop="lng" label="所在经度" align="center"></el-table-column>
                                <el-table-column prop="lat" label="所在纬度" align="center"></el-table-column>
                                <el-table-column label="操作" align="center">
                                    <template slot-scope="scope">
                                        <el-button type="danger" size="mini" @click="handleDelete(scope.row)">删除</el-button>
                                    </template>
                                </el-table-column>
                            </el-table>
                            <!--分页条-->
                            <div class="pagination-container">
                                <el-pagination
                                        class="pagiantion"
                                        @current-change="handleCurrentChange"
                                        :current-page="pagination.currentPage"
                                        :page-size="pagination.pageSize"
                                        layout="total, prev, pager, next, jumper"
                                        :total="pagination.total">
                                </el-pagination>
                            </div>
                            <!--新建,新增地址-->
                            <div class="add-form" style="height: 500px;width: 600px">
                                <el-dialog title="新增地址" :visible.sync="dialogFormVisible" @opened="map2">
                                    <div>
                                        <div id="r-result" ><input type="text" id="suggestId" size="25" placeholder="请输入地址" style="width:300px;height: 32px;" />
                                            <el-button type="primary" class="butT" @click="handleAdd()" >确定添加</el-button>
                                        </div>
                                    </div>
                                    <div id="searchResultPanel" style="border:1px solid #C0C0C0;width:150px;height:auto; display:none;"></div>
                                    <div style="height: 400px;width: 500px" id="2-map"></div>
                                </el-dialog>
                            </div>

                        </el-tab-pane>
                    </el-tabs>
                </template>
                </el-dialog>
            </div>
        </div>
    </div>
</div>
</body>

<script>
    var vue = new Vue({
        el: '#app',
        data:{
            activeName:'first',//添加/编辑窗口Tab标签名称
            pagination: {//分页相关属性
                currentPage: 1,
                pageSize:10,
                total:100,
                queryString:null,
            },
            value: {
                address: "",
                lng: "",
                lat: "",
            },
            dataList: [],//列表数据
            formData: {},//表单数据
            tableData:[],//新增和编辑表单中对应的检查项列表数据
            dialogFormVisible: false,//控制添加窗口显示/隐藏
            ListAddress: []
        },
        created() {
            this.findPage();
            this.findAll();
        },
        mounted(){
            this.map()
        },
        methods: {
            //
            map2(){
                var map = new BMap.Map("2-map");
                map.centerAndZoom(new BMap.Point(114.305475,30.540708), 13);
                map.enableScrollWheelZoom(true);
                function G(id) {
                    return document.getElementById(id);
                }

                // var map = new BMap.Map("l-map");
                // map.centerAndZoom("北京",12);                   // 初始化地图,设置城市和地图级别。

                var ac = new BMap.Autocomplete(    //建立一个自动完成的对象
                    {"input" : "suggestId"
                        ,"location" : map
                    });

                ac.addEventListener("onhighlight", function(e) {  //鼠标放在下拉列表上的事件
                    var str = "";
                    var _value = e.fromitem.value;
                    var value = "";
                    if (e.fromitem.index > -1) {
                        value = _value.province +  _value.city +  _value.district +  _value.street +  _value.business;
                    }
                    str = "FromItem<br />index = " + e.fromitem.index + "<br />value = " + value;

                    value = "";
                    if (e.toitem.index > -1) {
                        _value = e.toitem.value;
                        value = _value.province +  _value.city +  _value.district +  _value.street +  _value.business;
                    }
                    str += "<br />ToItem<br />index = " + e.toitem.index + "<br />value = " + value;
                    G("searchResultPanel").innerHTML = str;
                });

                var myValue;
                ac.addEventListener("onconfirm", function(e) {    //鼠标点击下拉列表后的事件
                    var _value = e.item.value;
                    myValue = _value.province +  _value.city +  _value.district +  _value.street +  _value.business;
                    G("searchResultPanel").innerHTML ="onconfirm<br />index = " + e.item.index + "<br />myValue = " + myValue;
                    vue.value.address = myValue;
                    setPlace();
                });

                function setPlace() {
                    map.clearOverlays();    //清除地图上所有覆盖物
                    function myFun() {
                        var pp = local.getResults().getPoi(0).point;    //获取第一个智能搜索的结果
                        map.centerAndZoom(pp, 18);
                        map.addOverlay(new BMap.Marker(pp));    //添加标注
                        console.log(pp)
                        vue.value.lat = pp.lat;
                        vue.value.lng = pp.lng;
                    }

                    var local = new BMap.LocalSearch(map, { //智能搜索
                        onSearchComplete: myFun
                    });
                    local.search(myValue);
                }
            },
            map(){
                // 百度地图API功能
                var map = new BMap.Map("l-map");
                map.centerAndZoom(new BMap.Point(114.305475,30.540708), 8);
                map.enableScrollWheelZoom(true);
                var index = 0;
                var myGeo = new BMap.Geocoder();
                var adds = new Array();
                for (let i = 0; i < this.ListAddress.length; i++) {
                    adds.push(new BMap.Point(this.ListAddress[i].lng, this.ListAddress[i].lat));
                }
                for (var i = 0; i < adds.length; i++) {
                    var marker = new BMap.Marker(adds[i]);
                    map.addOverlay(marker);
                    marker.setLabel(new BMap.Label(this.ListAddress[i].address, {offset: new BMap.Size(20, -10)}));
                }
                function bdGEO() {
                    var pt = adds[index];
                    geocodeSearch(pt);
                    index++;
                }

                function geocodeSearch(pt) {
                    if (index < adds.length - 1) {
                        setTimeout(window.bdGEO, 400);
                    }
                    myGeo.getLocation(pt, function (rs) {
                        var addComp = rs.addressComponents;
                        document.getElementById("result").innerHTML += index + ". " + adds[index - 1].lng + "," + adds[index - 1].lat + "：" + "商圈(" + rs.business + ")  结构化数据(" + addComp.province + ", " + addComp.city + ", " + addComp.district + ", " + addComp.street + ", " + addComp.streetNumber + ")<br/><br/>";
                    });
                }
                // [
                //     new BMap.Point(116.307852,40.057031),
                //     new BMap.Point(116.313082,40.047674),
                //     new BMap.Point(116.328749,40.026922),
                //     new BMap.Point(116.347571,39.988698),
                //     new BMap.Point(116.316163,39.997753),
                //     new BMap.Point(116.345867,39.998333),
                //     new BMap.Point(116.403472,39.999411),
                //     new BMap.Point(116.307901,40.05901)
                // ];
                // for(var i = 0; i<adds.length; i++){
                //     var marker = new BMap.Marker(adds[i]);
                //     map.addOverlay(marker);
                //     marker.setLabel(new BMap.Label("我是商圈:"+(i+1),{offset:new BMap.Size(20,-10)}));
                // }
            },

            //添加
            handleAdd() {
                var th=this;
                this.dialogFormVisible = false;
                axios.post("/map/add.do", vue.value).then((res) => {
                    console.log(vue.value)
                    if (res.data.flag) {
                        this.findPage();
                        //弹出提示信息
                        this.$message({
                            message: res.data.message,
                            type: 'success'
                        });
                    } else {
                        //弹出提示
                        this.$message.error(res.data.message);
                    }
                });
            },
            //分页查询
            findPage() {
                //封装分页参数
                var param = {
                    currentPage:this.pagination.currentPage,
                    pageSize:this.pagination.pageSize,
                    queryString:this.pagination.queryString
                };


                //发送ajax请求，提交分页相关参数
                axios.post("/map/findPage.do",param).then((res) => {
                    //为VUE对象的模型数据赋值，基于双向数据绑定展示到页面
                    this.dataList = res.data.rows;//当前页展示的数据集合
                    this.pagination.total = res.data.total;//总数据量
                });
            },
            // 重置表单
            resetForm() {
                this.formData = {};
            },
            // 弹出添加窗口
            handleCreate() {

                this.resetForm();
                this.dialogFormVisible=true;
                //this.map2();
            },
            //切换页码
            handleCurrentChange(currentPage) {
                //为模型数据赋值（当前页面）
                this.pagination.currentPage = currentPage;
                this.findPage();
            },
            // 删除
            handleDelete(row) {//row其实是一个json对象，json对象的结构为{"age":"0-100","attention":"无","code":"0011","id":38,"name":"白细胞计数","price":10.0,"remark":"白细胞计数","sex":"0","type":"2"}
                //alert(row.id);
                this.$confirm("你确定要删除当前数据吗？","提示",{//确认框
                    type:'warning'
                }).then(()=>{
                    //用户点击确定按钮，发送ajax请求，将检查项ID提交到Controller进行处理
                    axios.get("/map/delete.do?id=" + row.id).then((res) => {
                        if(res.data.flag){
                            //执行成功
                            //弹出成功提示信息
                            this.$message({
                                type:'success',
                                message:res.data.message
                            });
                            //重新进行分页查询
                            this.findPage();
                        }else{
                            //执行失败
                            this.$message.error(res.data.message);
                        }
                    }).catch((r)=>{
                        this.showMessage(r);
                    });
                }).catch(()=>{
                    this.$message({
                        type:'info',
                        message:'操作已取消'
                    });
                });
            },
            findAll() {
                axios.get("/map/findAll.do").then((res) => {
                    if (res.data.flag) {
                        this.ListAddress = res.data.data;
                        this.map();
                    } else {
                        this.$message.error(res.data.message);
                    }
                })
            },
            handleRemove(){
                this.map;
                this.findPage();
                this.findAll();
            }
        }
    })
</script>
</html>


